// plugin/components/word-box/index.js
/** 获取插件方法 */
const plugin = require('../../index');
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    word: {
      type: String,
      observer: async function (newVal, oldVal) {
        let baseword = newVal
        if (baseword.length >= 1) {
          //长度复核
          // this.reqWord();
          let ans = await plugin.wordQuery(baseword)
          console.log(ans)
          this.setData({
            item: ans.data
          })
        }
      }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    read() {
      const innerAudioContext = wx.createInnerAudioContext()
      innerAudioContext.autoplay = true
      innerAudioContext.src = 'https://dict.youdao.com/dictvoice?type=1&audio=' + this.properties.word
      innerAudioContext.onPlay(() => {})
      innerAudioContext.onError((res) => {
        console.log(res.errMsg)
        console.log(res.errCode)
      })
    },
  }
})